//index_cacu_opt.js

var memory
var imported = {
    memory:new WebAssembly.Memory({initial : 1}),
    abort :function (a,b,c,d) {console.log("abort")},
    sin :Math.sin
    //"performance.now": () => performance.now() , // 提供 performance.now 的替代实现
    //"console.log": () => console.log()

}
// wasi
function test(file ,func)
{
    const bytes = readbuffer(file); 
    const mod = new WebAssembly.Module(bytes);
    const instance = new WebAssembly.Instance(mod, {env: imported});
    memory = instance.exports.memory;

    const startTime = performance.now();
    const outPtr = instance.exports[func]();
    const endTime = performance.now();

    
    console.log(`calculate time: ${(endTime - startTime)} ms`);
    const Output = new Uint8Array(memory.buffer, outPtr ,256*256*4);
    console.log(Output);

} 

test("build/ColorCalculator.wasm","runOnce");
